import { CARDS_TO_ASCII_STR } from "../app/svr_game/nbdoudizhu/GameDefine";
import {GameLogic} from "../app/svr_game/nbdoudizhu/GameLogic";
import {CARD_INVALID} from "../app/svr_game/nbdoudizhu/GameDefine";

let gameLogic = new GameLogic();

function assert(condition: any, msg?: string): asserts condition {
    if (!condition) {
        console.error(msg)
    }
}

function test_er_shun_cai_shen() {
    let array = [
        [0x03,0x03,0x01,0x01]
    ]
    for(let i=0;i<array.length;i++){
        assert(gameLogic.is_er_shun_cai_shen_123(array[i],2),CARDS_TO_ASCII_STR(array[i])+"不是三带对")
    }
}

function test_san_shun_cai_shen() {
    let array = [
        [0x03,0x03,0x03,0x01,0x01,0x01]
    ]
    for(let i=0;i<array.length;i++){
        assert(gameLogic.is_san_shun_cai_shen_123(array[i],3),CARDS_TO_ASCII_STR(array[i])+"不是三带对")
    }
}

function test_san_dai_er() {
    let array = [
        [0x03,0x03,0x03,0x02,0x02],
        [0x01,0x01,0x01,0x02,0x02],
        [0x02,0x02,0x02,0x08,0x08],
    ]
    for(let i=0;i<array.length;i++){
        assert(gameLogic.is_san_dai_dui(array[i]),CARDS_TO_ASCII_STR(array[i])+"不是三带对")
    }
}

function test_san_dai_er_caishen() {
    let array = [
        [0x03,0x03,0x03,0x02],
        [0x01,0x02,0x02],
        [0x02,0x08],
        [0x02],
    ]
    assert(gameLogic.is_san_dai_dui_cai_shen(array[0],1)==0x03,CARDS_TO_ASCII_STR(array[0])+"不是三带对")
    assert(gameLogic.is_san_dai_dui_cai_shen(array[1],2)==0x02,CARDS_TO_ASCII_STR(array[1])+"不是三带对")
    assert(gameLogic.is_san_dai_dui_cai_shen(array[2],3)==0x02,CARDS_TO_ASCII_STR(array[2])+"不是三带对")
    assert(gameLogic.is_san_dai_dui_cai_shen(array[3],4)==0x02,CARDS_TO_ASCII_STR(array[3])+"不是三带对")
}

function test_fei_ji_wing() {
    let array = [
        [0x03,0x03,0x03,0x02,0x02,0x02,0x01,0x01,0x04,0x04],
        [0x03,0x03,0x03,0x02,0x02,0x02,0x01,0x01,0x01,0x04,0x04,0x05,0x05,0x06,0x06],
        [0x02,0x02,0x02,0x01,0x01,0x01,0x0b,0x0b,0x0c,0x0c],
        [0x03,0x03,0x03,0x02,0x02,0x02,0x01,0x01,0x0d,0x0d],
        [0x01,0x01,0x01,0x0d,0x0d,0x0d,0x03,0x03,0x02,0x02]
    ]
    assert(gameLogic.is_fei_ji_wing(array[0])==CARD_INVALID,CARDS_TO_ASCII_STR(array[0])+"判断错误")
    assert(gameLogic.is_fei_ji_wing(array[1])==0x01,CARDS_TO_ASCII_STR(array[1])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing(array[2])==0x01,CARDS_TO_ASCII_STR(array[2])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing(array[3])==0x02,CARDS_TO_ASCII_STR(array[3])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing(array[4])==0x0d,CARDS_TO_ASCII_STR(array[4])+"不是蝴蝶")
}

function test_fei_ji_wing_caishen() {
    let array = [
        [0x03,0x03,0x03,0x02,0x02,0x02,0x01,0x01],
        [0x03,0x03,0x03,0x01,0x01,0x01,0x04,0x04,0x05,0x05,0x06,0x06],
        [0x02,0x02,0x01,0x01,0x0b,0x0b,0x0c,0x0c],
        [0x03,0x03,0x03,0x02,0x02,0x02,0x01,0x0d,0x0d],
        [0x01,0x0d,0x0d,0x0d,0x03,0x03]
    ]
    assert(gameLogic.is_fei_ji_wing_cai_shen(array[0],2)==0x02,CARDS_TO_ASCII_STR(array[0])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing_cai_shen(array[1],3)==0x01,CARDS_TO_ASCII_STR(array[1])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing_cai_shen(array[2],2)==0x0b,CARDS_TO_ASCII_STR(array[2])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing_cai_shen(array[3],1)==0x02,CARDS_TO_ASCII_STR(array[3])+"不是蝴蝶")
    assert(gameLogic.is_fei_ji_wing_cai_shen(array[4],4)==0x0d,CARDS_TO_ASCII_STR(array[4])+"不是蝴蝶")
}

export function testNbddz() {
    test_er_shun_cai_shen();
    test_san_shun_cai_shen()
    test_san_dai_er()
    test_san_dai_er_caishen()
    test_fei_ji_wing()
    test_fei_ji_wing_caishen()
}